using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class CoinShopManager : MonoBehaviour
{
	public GameObject tabGold;

	public GameObject tabCash;

	public GameObject tabFree;

	public GameObject[] buttonFreeMoney;

	public UITexture bgDollar;

	public UITexture bgGold;

	public UIGrid miniStarterPacksUIGrid;

	public MiniStarterPackUI miniStarterPackUI;

	private List<MiniStarterPackUI> miniStarterPackButtons = new List<MiniStarterPackUI>();

	public void OpenTabGold()
	{
		if (SceneManager.GetActiveScene().name.Equals("Lobby"))
		{
			ShowButtonFreeMoney(true);
		}
		else
		{
			ShowButtonFreeMoney(false);
		}
		tabGold.SetActive(true);
		tabCash.SetActive(false);
		bgGold.enabled = true;
		bgDollar.enabled = false;
		UpdateMiniStarterPackButtons();
	}

	public void OpenTabCash()
	{
		if (SceneManager.GetActiveScene().name.Equals("Lobby"))
		{
			ShowButtonFreeMoney(true);
		}
		else
		{
			ShowButtonFreeMoney(false);
		}
		tabGold.SetActive(false);
		tabCash.SetActive(true);
		bgGold.enabled = false;
		bgDollar.enabled = true;
	}

	public void OpenTabFree()
	{
		if (FyberWrapper.instance != null)
		{
			FyberWrapper.instance.CheckRewardedVideo(RVRequestLocation.OpenTab);
		}
		if (MarketControllerUI.instance != null)
		{
			MarketControllerUI.instance.ShowFreeHolder();
		}
	}

	private void ShowButtonFreeMoney(bool val)
	{
		GameObject[] array = buttonFreeMoney;
		foreach (GameObject gameObject in array)
		{
			gameObject.SetActive(val);
		}
	}

	public void UpdateMiniStarterPackButtons()
	{
		ClearMiniStarterPackButtons();
		int num = 0;
		foreach (StarterPack availableStarterPack in StarterPacksManager.instance.availableStarterPacks)
		{
			if (availableStarterPack.availableForPurcase && availableStarterPack.IsGood())
			{
				AddMiniStarterPackButton(availableStarterPack, num.ToString());
				num++;
			}
		}
		miniStarterPacksUIGrid.repositionNow = true;
	}

	private void ClearMiniStarterPackButtons()
	{
		foreach (MiniStarterPackUI miniStarterPackButton in miniStarterPackButtons)
		{
			Object.Destroy(miniStarterPackButton.gameObject);
		}
		miniStarterPackButtons.Clear();
	}

	private void AddMiniStarterPackButton(StarterPack starterPack, string name)
	{
		name = "00" + name;
		MiniStarterPackUI miniStarterPackUI = Object.Instantiate(this.miniStarterPackUI);
		miniStarterPackUI.transform.SetParent(miniStarterPacksUIGrid.transform);
		miniStarterPackUI.transform.localPosition = Vector3.zero;
		miniStarterPackUI.transform.localScale = Vector3.one;
		miniStarterPackUI.name = name;
		miniStarterPackUI.Init(starterPack);
		miniStarterPackUI.SetRewards(1f, miniStarterPackUI.dafaultRewardGrid, miniStarterPackUI.starterPack.rewards, true, 4);
		miniStarterPackButtons.Add(miniStarterPackUI);
		miniStarterPackUI.gameObject.SetActive(true);
	}
}
